/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-09-29
*/
package com.rzico.order.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.entity.Filter;
import com.rzico.entity.Pageable;
import com.rzico.entity.PageResult;
import com.rzico.order.entity.BargainOrder;
import com.rzico.order.entity.BargainPeriod;
import com.rzico.order.entity.BargainProduct;
import com.rzico.order.service.BargainOrderService;
import com.rzico.order.service.BargainPeriodService;
import com.rzico.order.service.BargainProductService;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.Api;
import com.rzico.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;

/**
 * 砍价期数接口
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-09-29
 */
@Api(description = "砍价期数接口")
@RestController
@RequestMapping("/admin/bargainPeriod")
public class BargainPeriodAdminController extends BaseController {

    @Autowired
    private BargainPeriodService bargainPeriodService;

    @Autowired
    private BargainOrderService bargainOrderService;


    /**
     * 分页查询团购期数
     *
     * @return
     */

    @ApiOperation("分页查询团购期数")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bargainBuyId", value = "砍价ID", dataType = "String", paramType = "query")
    })
    public CommResult<BargainPeriod> list(Long bargainBuyId, Pageable pageable) {
        Map<String, Object> params = new HashMap<String, Object>();
        params = buildSortField(params, pageable);
        if (bargainBuyId!=null){
            params.put("bargainBuyId", bargainBuyId);
        }

        Page<Object> startPage = PageHelper.startPage(pageable.getPageNum(), pageable.getPageSize());
        List<BargainPeriod> list = bargainPeriodService.selectList(params);
        PageResult<BargainPeriod> pageResult = new PageResult<BargainPeriod>(list, startPage.getTotal(), pageable);
        return CommResult.success(pageResult);
    }

    /**
     * 查询历史订单
     *
     * @return
     */
    @ApiOperation("查询历史订单")
    @GetMapping("/getOrderList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "periodId", value = "期ID", dataType = "String", paramType = "query")
    })
    public CommResult<BargainOrder> getOrderList(Long periodId) {
        Map<String,Object> data = new HashMap<>();
        data.put("orderItem",bargainOrderService.getOrderList(periodId));
        return CommResult.success(data);

    }

}
